<?php

App::uses('AppModel', 'Model');

/**
 * Project Model
 * 
 * PHP versions 5
 * CAKEPHP versions 2.x
 *
 * @author        TienVanVo <vantienvnn@gmail.com>
 * @link          
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 *
 */
class UserReward extends AppModel {

	/**
	 * Validation rules.
	 *
	 * @var array
	 */
	public $validate = array(
		'name' => array(
			'notempty' => array(
				'allowEmpty' => false,
				'rule' => 'notempty',
				'message' => 'This name is required',
				'required' => true,
			)
		),
		'reward_id' => array(
			'notempty' => array(
				'allowEmpty' => false,
				'rule' => 'notempty',
				'message' => 'This name is required',
				'required' => true,
			)
		),
		'user_id' => array(
			'notempty' => array(
				'allowEmpty' => false,
				'rule' => 'notempty',
				'message' => 'This name is required',
				'required' => true,
			)
		)
	);

	public function isPlayable() {
		$userID = AuthComponent::user('id');
		if (!$userID) {
			return false;
		}
		$user = $this->find('count', array('recursive' => -1,
			'conditions' => array('user_id' => $userID)));
		return !$user;
	}

}

?>